<template>
    <div class="app-container">
      <div class="search-div">
        <el-form label-width="70px" size="small">
          <el-row>
            <el-col :span="8">
              <el-form-item label="关 键 字">
                <el-input style="width: 95%" v-model="searchObj.keyword" placeholder="用户名/姓名/手机号码" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData()">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetData()">重置</el-button>
          </el-row>
          <el-row style="display: flex"> </el-row>
        </el-form>
      </div>
  
      <hr />
      <!-- 工具栏 -->
      <!-- <div class="tools-div">
        <el-button type="success" size="mini" @click="ShenHe()"
          >批量审核</el-button
        >
      </div> -->
      <!-- 列表 -->
      <el-table :data="list" stripe border style="width: 100%; margin-top: 10px" @selection-change="handleSelectionChange">
        <el-table-column type="selection" />
        <el-table-column label="序号" width="70" align="center">
          <template slot-scope="scope">
            {{ (page - 1) * limit + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="id" label="借款id" />
        <el-table-column prop="createuserId" label="借款人id" />
        <el-table-column prop="title" label="借款标题" />
        <el-table-column prop="bidrequestamount" label="借款金额" />
        <el-table-column prop="monthes2return" label="还款期限（月）" />
        <el-table-column prop="applytime" label="申请时间" />
        <el-table-column prop="bidrequeststate" label="借款状态">
          <template slot-scope="scope">
            {{ scope.row.bidrequeststate === 0 ? "未通过" : (scope.row.bidrequeststate === 1 ? "一审通过" : (scope.row.bidrequeststate === 2 ? "已通过" : "已拒绝")) }}
          </template>
        </el-table-column>
  
        <el-table-column label="操作" align="center" fixed="right" width="120">
          <template slot-scope="scope">
            <!-- <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeDataById(scope.row.id)"
                          title="删除" /> -->
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="checkLoanInfo(scope.row.id)" title="查看账户" />
            <el-button type="warning" icon="el-icon-baseball" size="mini" @click="checkShenHeHistory(scope.row.id)"
              title="查看审核历史" />
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination :current-page="page" :total="total" :page-size="limit" style="padding: 30px 0; text-align: center"
        layout="total, prev, pager, next, jumper" @current-change="fetchData" />
      <!-- 弹框2 审核历史 -->
      <el-dialog title="查看审核历史" :visible.sync="dialogVisible2" width="80%">
        <span slot="footer" class="dialog-footer">
          <el-table :data="list2" stripe border style="width: 100%; margin-top: 10px"
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" />
            <el-table-column label="序号" width="70" align="center">
              <template slot-scope="scope">
                {{ (page - 1) * limit + scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column prop="id" label="审核id" />
            <el-table-column prop="state" label="审核状态">
              <template slot-scope="scope">
                {{ scope.row.state === 0 ? "未通过" : (scope.row.state === 1 ? "一审通过" : (scope.row.state === 2 ? "已发标" : "已拒绝")) }}
              </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注" />
            <el-table-column prop="audittime" label="审核时间" />
            <el-table-column prop="applytime" label="申请时间" />
            <el-table-column prop="auditorId" label="审核人id" />
            <el-table-column prop="applierId" label="申请人id" />
            <el-table-column prop="bidrequestid" label="借款id" />
            <el-table-column prop="audittype" label="贷款类型" />
          </el-table>
        </span>
      </el-dialog>
  
      <!-- 弹框 -->
      <el-dialog title="查看申请信息" :visible.sync="dialogVisible" width="40%">
        <el-form ref="dataForm" :model="loanList" label-width="100px" size="small" style="padding-right: 40px">
          <el-form-item label="借款ID" prop="id">
            <el-input v-model="loanList.id" :readonly="true" />
          </el-form-item>
          <el-form-item label="版本号" prop="version">
            <el-input v-model="loanList.version" :readonly="true" />
          </el-form-item>
          <el-form-item label="借款类型" prop="bidrequesttype">
            <el-input v-model="loanList.bidrequesttype" :readonly="true" />
          </el-form-item>
  
          <el-form-item label="借款金额" prop="bidrequestamount">
            <el-input v-model="loanList.bidrequestamount" :readonly="true" />
          </el-form-item>
          <el-form-item label="当前利率" prop="currentrate">
            <el-input v-model="loanList.currentrate" :readonly="true" />
          </el-form-item>
          <el-form-item label="还款期限（月" prop="monthes2return">
            <el-input v-model="loanList.monthes2return" :readonly="true" />
          </el-form-item>
          <el-form-item label="投标次数" prop="bidCount">
            <el-input v-model="loanList.bidCount" :readonly="true" />
          </el-form-item>
          <el-form-item label="总回报金额" prop="totalrewardamount">
            <el-input v-model="loanList.totalrewardamount" :readonly="true" />
          </el-form-item>
          <el-form-item label="当前已投标金额" prop="currentsum">
            <el-input v-model="loanList.currentsum" :readonly="true" />
          </el-form-item>
          <el-form-item label="借款标题" prop="title">
            <el-input v-model="loanList.title" :readonly="true" />
          </el-form-item>
          <el-form-item label="借款描述" prop="description">
            <el-input v-model="loanList.description" :readonly="true" />
          </el-form-item>
          <el-form-item label="备注" prop="note">
            <el-input v-model="loanList.note" :readonly="true" />
          </el-form-item>
          <el-form-item label="截止日期" prop="disabledate">
            <el-input v-model="loanList.disabledate" :readonly="true" />
          </el-form-item>
          <el-form-item label="借款人ID" prop="createuser_id">
            <el-input v-model="loanList.id" :readonly="true" />
          </el-form-item>
          <el-form-item label="剩余天数" prop="disabledays">
            <el-input v-model="loanList.disabledays" :readonly="true" />
          </el-form-item>
          <el-form-item label="最小投标金额" prop="minbidamount">
            <el-input v-model="loanList.minbidamount" :readonly="true" />
          </el-form-item>
          <el-form-item label="申请时间" prop="applytime">
            <el-input v-model="loanList.applytime" :readonly="true" />
          </el-form-item>
          <el-form-item label="发布时间" prop="publishtime">
            <el-input v-model="loanList.publishtime" :readonly="true" />
          </el-form-item>
        </el-form>
  
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false" size="small" icon="el-icon-refresh-right">取 消</el-button>
        </span>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import api from "@/api/loanShenHe/loanShenHe.js";
  import api2 from "@/api/loanShenHe/loanShenHeHistory.js";
  const defaultFrom = {};
  export default {
    data() {
      return {
        listLoading: true, // 数据是否正在加载
        list: [], // 数据列表
        list2: [], // 审核数据列表
        total: 0, // 数据库中的总记录数
        page: 1, // 默认页码
        limit: 10, // 每页记录数
        searchObj: {}, // 查询表单对象
  
        dialogVisible: false,
        dialogVisible2: false,
        loanList: {},
        saveBtnDisabled: false,
  
        dialogRoleVisible: false,
        selectValueData: [],
      };
    },
    created() {
      this.fetchData();
    },
    methods: {
      // 重置表单
      resetData() {
        this.searchObj = {};
        this.fetchData();
      },
      fetchData(page = 1) {
        this.page = page;
        if (this.createTimes && this.createTimes.length == 2) {
          this.searchObj.createTimeBegin = this.createTimes[0];
          this.searchObj.createTimeEnd = this.createTimes[1];
        }
  
        api
          .getloanpublishList(this.page, this.limit, this.searchObj)
          .then((response) => {
            //this.list = response.data.list
            this.list = response.data.records;
            console.log(response.data.records);
            this.total = response.data.total;
            // 数据加载并绑定成功
            this.listLoading = false;
          });
      },
      handleSelectionChange(selectValue) {
        // console.log(selectValue);
        this.selectValueData = selectValue;
      },
  
      checkLoanInfo(id) {
        this.dialogVisible = true;
        api.findLoanById(id).then((response) => {
          this.loanList = response.data;
        });
      },
      // 查看审核历史记录
      checkShenHeHistory(id) {
        this.dialogVisible2 = true;
        api2.historyList(id).then((response) => {
          this.list2 = response.data.records
          console.log(response.data.records);
        })
      },
    },
  };
  </script>
  
  <style></style>
  